<?php
class guestbookAction extends security_normal {
	
	function action(){
		$miceSession = new session();
		global $conn;
		if($_POST){
			if($_POST['checkcode']<>$miceSession->get('checkcode')){
				MessageBox('验证码错误','back');
				exit;
			}

			if($_POST['name']==''){
				MessageBox('请填写姓名','back');
				exit;
			}

			if($_POST['title']==''){
				MessageBox('请填写标题','back');
				exit;
			}

			$form=new model_Form();
			
			
			if($miceSession->get('mu__userid')<1){
				$form->setUserId(0);
				$form->setName(MiceFilterHtml($_POST['name']));
			}else{
				$form->setUserId($miceSession->get('mu__userid'));
				$form->setName($miceSession->get('mu__loginname'));
			}
			$form->setEmail(MiceFilterHtml($_POST['email']));
			$form->setTitle(MiceFilterHtml($_POST['title']));
			$form->setCreatedat(time());
			$form->setType('guestbook');
			$form->setIp(GetRealIp());
			$form->setContent(MiceFilterQuote($_POST['content']));
			$results=$form->doInsert();
			
			if($results){
				MessageBox('提示信息','back','提交留言成功,需要管理员审核后才能显示');
			}else{
				MessageBox('提交留言失败','back');
			}
			exit;
		}

		$form2=new model_Form();
		$form2->setSubsection(' WHERE type=\'guestbook\' AND isopen=1 order by createdat DESC');
		$form2->setNrows(0);
		$form2->setOffset(20);
		$FormRS=$form2->doSelectLimit();

		$editor='';
		//调用插件
		$plugin=new model_Plugin();
		$plugin->setSubsection('WHERE isopen=1 AND hook=\'editor_fast\' ORDER BY orderid ASC,plugin_id DESC');
		$plugins=$plugin->doSelectOne();
		include_once MICE_DIR.'includes/plugin.php';
		if($plugins){
			if(file_exists(MICE_DIR.'plugins/'.$plugins->getName().'/index.php')){
				include_once MICE_DIR.'plugins/'.$plugins->getName().'/index.php';
				add_filter('editor_fast', $plugins->getName());
				$editor=apply_filters('editor_fast',0);
				remove_filter('editor_fast', $plugins->getName());
			}
		}

		if($editor==''){
			$editor='<textarea id="MCEname" name="MCEname" rows="15" cols="80" style="width: 100%">MCEcontent</textarea>';
		}

		$editor=str_replace('MCEname','content',$editor);
		$editor=str_replace('MCEcontent','',$editor);

		$smarty = new Smarty();
		$smarty->load_filter('pre','micePreCompileIndex');
		$smarty->assign("FormRS",$FormRS);
		$smarty->assign("editor",$editor);
		$smarty->assign("checkcode",MICE_URL.'code.php');

		$filename = new getTPLFileName(__CLASS__);
		$tpl=$filename->TPLFileName;
		$smarty->display($tpl);
	}	
}
?>